<?php
    require "config.php";
    $dbh = dbConnect();
    try{
       if($_POST){
        $sql = "insert into users(user_name,user_pwd) values(
            '".$_POST['username']."',
            '".$_POST['password']."'
            )";
        $sth = $dbh->query($sql);
        if($dbh){
            echo("<script>alert(\"注册成功。\");window.location.href='login.php'</script>");
        }else{
            echo("<script>alert(\"注册失败。\");window.location.href='regist.php'</script>");
        }  
       }  
    }catch(PDOException $e){
        print("Error".$e->getMessage());
        die();
    }
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>regist</title>
    <link rel="stylesheet" href="./css/regist.css">
</head>
<body class="regist-body">
    
    <div class="regist-form">
        <form action="regist.php" method="POST">
            <div class="regist-wrap-form" style="text-align: center;"><h1>Regist</h1></div>
            <div class="regist-wrap-form"><input type="text" class="regist-input-text" name="username" value="" placeholder="UserName"></div>
            <div class="regist-wrap-form"><input type="text" class="regist-input-text" name="password" value="" placeholder="Password"></div>
            <div class="regist-wrap-form regist-wrap-checkbox"><input type="checkbox" name="checkbox" class="regist-input-checkbox" value="remember">Remember me <input type="submit" name="regist-submit" value="regist" class="regist-input-submit"></div>            
        </form>
        <div class="regist-notice">
            <a href="login.php">前往登录页面</a>
        </div>
    </div>
</body>
</html>